﻿///////////////////////////////////////////////////////////////////////////////
// File:        ConnectionOutputStream.hpp
// Author:      671643387@qq.com
// Description:
///////////////////////////////////////////////////////////////////////////////

#ifndef NIO_NET_CONNECTIONOUTPUTSTREAM_HPP_
#define NIO_NET_CONNECTIONOUTPUTSTREAM_HPP_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <cassert>
#include <boost/function.hpp>
#include <nio/net/ConnectionStream.hpp>

namespace nio
{
    namespace net
    {
        class ConnectionOutputStream : public ConnectionStream
        {
        public:
            typedef ConnectionOutputStream self;
        public:
            ConnectionOutputStream(Socket& sock, unsigned int size = 1024 * 64);
            ConnectionOutputStream(Socket& sock, ByteBuffer buff, unsigned int size = 1024 * 64);
            virtual ~ConnectionOutputStream();

        public:
            int flush(void);

            unsigned int write(const char* buf, unsigned int length)
            {
                return ConnectionStream::write(buf, length);
            }

            void setSendBytsFN(boost::function<void(unsigned int)> fn)
            {
                sendBytsFN_ = fn;
            }

        private:
            boost::function<void(unsigned int)> sendBytsFN_;
        };

    }
}

#endif //NIO_NET_CONNECTIONOUTPUTSTREAM_HPP_
